package com.itheima.controller;


import com.itheima.commo.PageResult;
import com.itheima.commo.R;
import com.itheima.entity.Category;
import com.itheima.entity.Employee;
import com.itheima.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController  {

    @Autowired
    private CategoryService categoryService;

    /**
     * 新增    菜品、套餐分类
     *
     */
    @PostMapping
    public R<String> save(@RequestBody Category category){
        categoryService.save(category);
        return R.success("新增分类成功了");
    }


    /**
     * 分类信息分页查询
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public R<PageResult> findPage(@RequestParam(value = "page", defaultValue = "1") Long page,
                                  @RequestParam(value = "pageSize", defaultValue = "10") Long pageSize) {
        PageResult<Category> pageResult = categoryService.findPage(page, pageSize);
        return R.success(pageResult);
    }

    /**
     * 根据id分类删除数据
     * @param id
     * @return
     */
    @DeleteMapping
    public R<String> deleteById(Long id){
        categoryService.deleteById(id);
        return R.success("分类删除成功");
    }


    /**
     * 分类修改
     * @param category
     * @return
     */
    @PutMapping
    public R<String> update(@RequestBody Category category){
        categoryService.update(category);
        return R.success("分类修改成功");
    }


    /**
     * 分类列表查询
     */
    @GetMapping("/list")
    private R<List<Category>> list(Category category){
        return R.success(categoryService.list(category));
    }




}
